package tables

import (
	"github.com/GoAdminGroup/go-admin/context"
	"github.com/GoAdminGroup/go-admin/modules/db"
	"github.com/GoAdminGroup/go-admin/plugins/admin/modules/table"
	"github.com/GoAdminGroup/go-admin/template/types"
	"github.com/GoAdminGroup/go-admin/template/types/form"
)

func GetChannelsTable(ctx *context.Context) table.Table {
	tableName := "storage_channels"
	title := "Channels"

	channels := table.NewDefaultTable(table.DefaultConfigWithDriver("mysql"))


	thisInfo := channels.GetInfo()

	thisInfo.SetFilterFormLayout(form.LayoutThreeCol)

	thisInfo.AddField("ID", "id", db.Int).FieldFilterable().FieldSortable()
	thisInfo.AddField("Slug", "slug", db.Varchar).FieldFilterable().FieldSortable()
	thisInfo.AddField("Title", "title", db.Varchar).FieldFilterable().FieldSortable()
	thisInfo.AddField("Description", "description", db.Text).FieldFilterable().FieldSortable()
	// thisInfo.AddField("Created_by", "created_by", db.Int).FieldFilterable().FieldSortable()
	thisInfo.AddField("Sort", "sort", db.Tinyint).FieldFilterable().FieldSortable()
	thisInfo.AddField("Created_at", "created_at", db.Timestamp).FieldFilterable(types.FilterType{FormType: form.DatetimeRange}).FieldSortable()
	thisInfo.AddField("Updated_at", "updated_at", db.Timestamp).FieldFilterable(types.FilterType{FormType: form.DatetimeRange}).FieldSortable()
	// thisInfo.AddField("Deleted_at", "deleted_at", db.Timestamp).FieldFilterable(types.FilterType{FormType: form.DatetimeRange}).FieldSortable()

	thisInfo.SetTable(tableName).SetTitle(title).SetDescription("List")


	thisForm := channels.GetForm()

	thisForm.AddField("Id", "id", db.Int, form.Default).
		FieldDisableWhenCreate()
	thisForm.AddField("Slug", "slug", db.Varchar, form.Text).
		FieldDefault("0")
	thisForm.AddField("Title", "title", db.Varchar, form.Text).
		FieldDefault("0")

	thisForm.AddField("Config", "config", db.Text, form.TextArea)
	thisForm.AddField("Description", "description", db.Text, form.RichText)
	// thisForm.AddField("Created_by", "created_by", db.Int, form.Number)
	thisForm.AddField("Sort", "sort", db.Tinyint, form.Number)
	thisForm.AddField("Created_at", "created_at", db.Timestamp, form.Datetime).
		FieldHide().FieldNowWhenInsert()
	thisForm.AddField("Updated_at", "updated_at", db.Timestamp, form.Datetime).
		FieldHide().FieldNowWhenUpdate()
	// thisForm.AddField("Deleted_at", "deleted_at", db.Timestamp, form.Datetime)

	thisForm.SetTable(tableName).SetTitle(title).SetDescription("Edit")


	detail := channels.GetDetailFromInfo()

	detail.SetTable(tableName).SetTitle(title).SetDescription("Detail")


	return channels
}
